<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link href="/zbxa/assets/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="/zbxa/css/style.css"/>
    <link href="/zbxa/assets/css/codemirror.css" rel="stylesheet">
    <link rel="stylesheet" href="/zbxa/assets/css/ace.min.css"/>
    <link rel="stylesheet" href="/zbxa/font/css/font-awesome.min.css"/>
    <!--[if lte IE 8]>
    <link rel="stylesheet" href="/zbxa/assets/css/ace-ie.min.css"/>
    <![endif]-->
    <script src="/zbxa/js/jquery-1.9.1.min.js"></script>
    <script src="/zbxa/assets/js/bootstrap.min.js"></script>
    <script src="/zbxa/assets/js/typeahead-bs2.min.js"></script>
    <script src="/zbxa/js/lrtk.js" type="text/javascript"></script>
    <script src="/zbxa/assets/js/jquery.dataTables.min.js"></script>
    <script src="/zbxa/assets/js/jquery.dataTables.bootstrap.js"></script>
    <script src="/zbxa/assets/layer/layer.js" type="text/javascript"></script>
    <script src="/zbxa/assets/laydate/laydate.js" type="text/javascript"></script>
    <script src="/zbxa/js/H-ui.js" type="text/javascript"></script>
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/custom.form.css">
    <script src="/layui/layui.all.js"></script>
    <script src="/js/core.util.js"></script>

    <title>选案指标</title>
    <style>
        .newSongTi {
            font-family: '新宋体', SimSun, sans-serif;
        }
        .selected {
            background-color: rgba(98, 168, 209, 0.5);
        }
        .footer {
            position: fixed;
            bottom: 0;
            width: 100%;
            height: 60px; /* 设置 footer 的高度 */
            background-color: rgba(98, 168, 209, 0.5);
            color: white;
            text-align: center;
            line-height: 60px;
            display: flex; /* 使用 Flexbox 布局 */
            justify-content: center; /* 水平居中 */
            align-items: center; /* 垂直居中 */
        }
    </style>
</head>

<body>
<!-- 弹出层 -->
<div id="popup" style="display: none;">
    <form class="layui-form" lay-filter="popupForm">
        <div class="layui-form-item">
            <div class="layui-input-block">
                <select name="selectOption" id="selectOption" lay-verify="required">
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="submit">提交</button>
            </div>
        </div>
    </form>
</div>
<div class="clearfix">
    <input type="text" name="xafaId" id="xafaId" th:value="${xafaId}" hidden>
    <div class="article_style" id="article_style">
        <div id="scrollsidebar" class="left_Treeview">
            <div class="show_btn" id="rightArrow"><span></span></div>
            <div class="widget-box side_content">
                <!--    <div class="side_title"><a title="隐藏" class="close_btn" href="#" onclick="toggleZblx()"><span></span></a></div>-->
                <div class="side_list">
                    <div class="widget-header header-color-green2">
                        <h4 class="lighter smaller">指标类型</h4>
                    </div>
                    <div class="widget-body">
                        <ul class="b_P_Sort_list" id="zblxList">
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <!--文章列表-->
        <div class="Ads_list">
            <div class="article_list" id="checkboxContainer">
                <table class="table table-striped table-bordered table-hover">
                    <thead id="zbmxThead">
<!--                    <tr>-->
<!--                        <th width="25"><label><input id="checkAll" type="checkbox" value="checkAll" class="ace"><span class="lbl"></span></label></th>-->
<!--                        <th width="50px">所属分类</th>-->
<!--                        <th width="50px">标题</th>-->
<!--                        <th width="150px">简介</th>-->
<!--                    </tr>-->
                    </thead>
                    <tbody id="zbmxTbody">
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<div  id="showResNsr_div" hidden>
    <table class="layui-hide" id="showResNsr_table" lay-filter="showResNsr_table" hidden></table>
</div>
<script type="text/html" id="ajxxtool">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="ajxxRecord">查看</a>
</script>
<div class="footer">
    <div id="showRes" style="display: block">
        <span id="nr" class="newSongTi" style="display: block;margin-left: 15px;float: left;color: black">已选<span style="color: black" id="chooseCount">0</span>项，匹配纳税人<span id="nsrCount" style="color: black">0</span>户</span>
        <a  onclick="lookResaultNsr()" href="javascript:;" style="float: left;margin-left: 15px;margin-top:18px;padding: 0px 0px;" class="btn btn-xs btn-info" >查 看 结 果</a>
    </div>
</div>
</body>
</html>
<script>
    // 获取token
    let token = CoreUtil.getData("access_token");
    // 地址栏转义token中的#号
    let tokenQuery = token.replace("#", "%23");
    let tableIns1;
    let table = layui.table;
    let form = layui.form;
    let layer = layui.layer;
    let $ = jQuery = layui.jquery;
    let laydate = layui.laydate;
    let upload = layui.upload;
    let element = layui.element;
    let levelFirst_table;
    let checkedmxIds = [];
    let choosed = 0;
    let xafaId;
    let xafaId_local;
    //********************
    $(document).ready(function(){
        $('#checkboxContainer').on('change', 'input[type="checkbox"]', function(){
            if ($(this).is(':checked')) {
                if($(this).val().indexOf('checkAll')==-1){
                    checkedmxIds.push($(this).val());
                    choosed++;
                }
            } else {
                if($(this).val().indexOf('checkAll')==-1){
                    choosed--;
                }
                let index = checkedmxIds.indexOf($(this).val());
                if (index > -1) {
                    checkedmxIds.splice(index, 1);
                }
            }
            $('#chooseCount').text(choosed);
            $('#showRes').css('display', 'block');
            console.log('选中的复选框 id：' + checkedmxIds);
            layui.use('table', function(){
                table.render({
                    elem: '#showResNsr_table'
                    , loading: false
                    , page: false //开启分页
                    ,contentType: 'application/json'
                    , headers: {"authorization": token}
                    ,where :{"zbmxIds":checkedmxIds}
                    , url: '/attention/zbxa/getNsrListByZbmxIds' //数据接口
                    , method: 'POST'
                    , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                        let nsrcount=res.data.total;
                        $('#nsrCount').text(nsrcount);
                        return {
                            "code": res.code, //解析接口状态
                            "msg": res.msg, //解析提示文本
                            "count": CoreUtil.isEmpty(res.data) ? 0 :nsrcount, //解析数据长度
                            "data": CoreUtil.isEmpty(res.data) ? null : res.data.records //解析数据列表
                        }
                    }
                    , cols: [
                        [
                            {type: 'checkbox', fixed: 'left'},
                            {field: 'djxh', title: '登记序号',width:250},
                            {field: 'nsrsbh', title: '纳税人识别号',width:250},
                            {field: 'nsrmc', title: '纳税人名称',width:250},
                            {field: 'shxydm', title: '社会信用代码',width:250},
                            {toolbar: '#ajxxtool', title: '操作',width: 100,align : 'center'}
                        ]
                    ]
                });
            });
        });
    });
    //********************
    layui.config({
        base: '/'
    }).extend({
        tableMerge: 'layui-ext/tableMerge/tableMerge'
    }).use(['table', 'layer', 'laydate', 'upload', 'element','tableMerge'], function () {

        //初始化重点行业
        CoreUtil.sendPost("/zbxaXafa/getXafas", null, function(res) {
            let datas = res.data;
            let options = "";
            for (let i = 0; i < datas.length; i++) {
                options += '<option value="' + datas[i].id + '">' + datas[i].name + '</option>';
            }
            $('#selectOption').append(options);
            // 更新select渲染
            form.render('select');
        });

        xafaId = $("#xafaId").val()
        if(xafaId == '0'){
// 弹出框
            var popupIndex =layer.open({
                type: 1,
                title: '请选择选案方案',
                content: $('#popup'),
                area: ['600px', '400px'],
                closeBtn: 0,
                success: function(){
                    // 表单渲染
                    form.render();
                }
            });
        }
        // 监听表单提交
        form.on('submit(submit)', function(data){
            var value = data.field.selectOption; // 获取选择框的值
            // 这里可以根据选择的值进行相应的操作，例如跳转页面等
            if(value == ""){
                layer.msg('您没有审批通过的选案方案！');
                return false;
            }
            xafaId_local = value;
            layer.close(popupIndex);
            return false; // 阻止表单跳转
        });

        let whereParams = {"zbmxIds":""};
        tableIns1 =  table.render({
            elem: '#showResNsr_table'
            , loading: false
            , page: false //开启分页
            ,contentType: 'application/json'
            , headers: {"authorization": token}
            ,where :whereParams
            , url: '/attention/zbxa/getNsrListByZbmxIds' //数据接口
            , method: 'POST'
            , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res.data) ? null : res.data.records //解析数据列表
                }
            }
            , cols: [
                [
                    {field: 'djxh', title: '登记序号',width:250},
                    {field: 'nsrsbh', title: '纳税人识别号',width:250},
                    {field: 'nsrmc', title: '纳税人名称',width:250},
                    {field: 'shxydm', title: '社会信用代码',width:250}
                ]
            ]
        });
    });
    function lookResaultNsr(){
        xafaId = $("#xafaId").val()
        if(xafaId == '0'){
            xafaId = xafaId_local;
        }
        layui.use('layer', function(){
        layer.open({
            type : 1,
            skin : 'layui-layer-molv',
            title : '指标筛选结果',
            area : [ '100%', '100%' ],
            shade : 0.8,
            shadeClose : true,
            content : jQuery("#showResNsr_div"),
            btn : [ '保存筛选结果','取消' ],
            yes: function(index, layero) {
                    let checkStatus = table.checkStatus('showResNsr_table');
                    let tableData = checkStatus.data;
                if (tableData.length > 0) {
                    //处理保存结果起名字
                    layer.prompt({
                        formType:0,
                        title: '请输入本次保存筛选结果名称',
                        area: ['800px', '350px'] //自定义文本域宽高
                    }, function(value, index, elem){
                        let reqData={"xazbNsrList":tableData,"zbmxIds":checkedmxIds,"resname":value,"xafaId":xafaId};
                        CoreUtil.sendPost("/attention/zbxa/saveXazbNsrList", reqData, function (res) {
                            let code = res.code;
                            if(code == 0){
                                layui.use('layer', function(){
                                    let layer = layui.layer;
                                    layer.msg('保存成功', {icon: 1, time: 2000}, function(){
                                    });
                                });
                            }else {
                                layui.use('layer', function(){
                                    let layer = layui.layer;
                                    layer.msg('保存失败，请稍后再试！', {icon: 1, time: 2000}, function(){
                                    });
                                });
                            }
                        });
                        layer.close(index);
                    },function(index, elem){
                        console.log('点击了取消按钮');
                        layer.close(index);
                    });
                }else {
                    layer.msg("请选择需要保存的纳税人！");  //如果未选择数据，则提示。
                }
            }
        });
        });
    }

    //初始化指标类型数据
    $(function () {
        CoreUtil.sendPost("/attention/zbxa/zblxList", null, function (res) {
            let resZblxList = res.data;
            $.each(resZblxList, function (index, item) {
                let listItem = $("<li></li>");
                let icon = $("<i></i> ").addClass("fa fa-newspaper-o pink");
                let link = $("<a></a>").attr("href", "#").attr("onclick", "getZbMxListByZblxId(" + item.id + ")").text(' ' + item.name).click(function() {
                    $("li").removeClass("selected");
                    $(this).closest("li").toggleClass("selected");
                });;
                listItem.append(icon, link);
                $("#zblxList").append(listItem);
            });
        });
    });


    function getZbMxListByZblxId(zblxId) {
        $('#zbmxThead').empty();
        $('#zbmxTbody').empty();
        let theadItemHtml = "<tr>\n" +
            "    <th width='25px'></th>\n" +
            "    <th width='50px'>所属分类</th>\n" +
            "    <th width='50px'>标题</th>\n" +
            "    <th width='100px'>简介</th>\n" +
            "    <th width='100px'>操作</th>\n" +
            "</tr>";
        $('#zbmxThead').append(theadItemHtml);
        CoreUtil.sendPost("/attention/zbxa/getZbMxListByZblxId", {"xazbdlid": zblxId}, function (res) {
            let datas = res.data;
            datas.forEach(function (item) {
                let tbodyItemHtml = "<tr><td><label><input type='checkbox' class='ace' value="+item.id+"><span class='lbl'></span></label></td>" +
                    "<td>" + item.xazbdlname + "</td>" +
                    "<td>" + item.name + "</td>" +
                    "<td class='displayPart' displayLength='60'>" + item.description + "</td>" +
                     "<td>" +'<button class="btn btn-xs btn-info" onclick="lookZbDetail(\'' + item.id + '\')">详细信息</button>'; + "</td>" +
                //'<td><a  onclick="lookResaultNsr('+item.id+') href="javascript:;  class="btn btn-xs btn-info" >查看结果</a><td>'+
                    "</tr>";
                checkedmxIds.forEach(function(id) {
                    if(item.id == id){
                        tbodyItemHtml = "<tr><td><label><input type='checkbox' checked class='ace' value="+item.id+"><span class='lbl'></span></label></td>" +
                            "<td>" + item.xazbdlname + "</td>" +
                            "<td>" + item.name + "</td>" +
                            "<td class='displayPart' displayLength='60'>" + item.description + "</td>" +
                            "<td>" +'<button class="btn btn-xs btn-info" onclick="lookZbDetail(\'' + item.id + '\')">详细信息</button>'; + "</td>" +
                        //  '<td><a  onclick="lookResaultNsr('+item.id+') href="javascript:;  class="btn btn-xs btn-info" >查看结果</a><td>'+

                            "</tr>";
                    }
                });
                $('#zbmxTbody').append(tbodyItemHtml);
            });
        });
    }
    function lookZbDetail(){

    }
    //面包屑返回值
    let index = parent.layer.getFrameIndex(window.name);
    parent.layer.iframeAuto(index);
    $('#add_page').on('click', function () {
        let cname = $(this).attr("title");
        let chref = $(this).attr("href");
        let cnames = parent.$('.Current_page').html();
        let herf = parent.$("#iframe").attr("src");
        parent.$('#parentIframe').html(cname);
        parent.$('#iframe').attr("src", chref).ready();
        ;
        parent.$('#parentIframe').css("display", "inline-block");
        parent.$('.Current_page').attr({"name": herf, "href": "javascript:void(0)"}).css({
            "color": "#4c8fbd",
            "cursor": "pointer"
        });
        parent.layer.close(index);

    });
    $(function () {
        let oTable1 = $('#sample-table').dataTable({
            "bStateSave": true,//状态保存
            "aoColumnDefs": [
                //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                {"orderable": false, "aTargets": [0, 2, 3, 4, 5, 7,]}// 制定列不参与排序
            ]
        });
        $('table th input:checkbox').on('click', function () {
            let that = this;
            $(this).closest('table').find('tr > td:first-child input:checkbox')
                .each(function () {
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });

        });
    })

    $(function () {
        $("#article_style").fix({
            float: 'left',
            //minStatue : true,
            skin: 'green',
            durationTime: false,
            stylewidth: '220',
            spacingw: 30,//设置隐藏时的距离
            spacingh: 250,//设置显示时间距
            set_scrollsidebar: '.Ads_style',
            table_menu: '.Ads_list'
        });
    });
    //初始化宽度、高度
    $(".widget-box").height($(window).height());
    $(".Ads_list").width($(window).width() - 220);
    //当文档窗口发生改变时 触发
    $(window).resize(function () {
        $(".widget-box").height($(window).height());
        $(".Ads_list").width($(window).width() - 220);
    });

    /*文章-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', {icon: 0,}, function (index) {
            $(obj).parents("tr").remove();
            layer.msg('已删除!', {icon: 1, time: 1000});
        });
    }
</script>
